//
//  XLHomeViewModel.m
//  XiangLove
//
//  Created by Dgh Hv on 2018/10/19.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLHomeViewModel.h"
#import "XLWheelFortunModel.h"
#import "XLWheelRecordModel.h"
#import "XLUserShareModel.h"
@implementation XLHomeViewModel

-(void)getWheelFortunInfoComplete:(void(^)(XLWheelFortunModel *model))complete
{
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"api/v2/UserInfo/GetWheelFortune" parameters:@{@"userId":[[XLAccountManager shareInstance]model].Id} resultClass:nil] subscribeNext:^(id x) {
        NSDictionary * dict = (NSDictionary *)x;
        if(ValidDict(dict))
        {
            XLWheelFortunModel * model = [XLWheelFortunModel modelWithDictionary:dict];
            if(complete)
            {
                complete(model);
            }
        }else
        {
            if(complete)
            {
                complete(nil);
            }
        }
        
    } error:^(NSError *error) {
        NSLog(@"%@", error);
        if(complete)
        {
            complete(nil);
        }
    }];
}

-(void)getWheelRewardInfoComplete:(void(^)(NSString * awardID))complete
{
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"/Api/v2/UserInfo/GetWheelReward" parameters:@{@"userId":[[XLAccountManager shareInstance]model].Id} resultClass:nil] subscribeNext:^(id x) {
        NSDictionary * dict = (NSDictionary *)x;
        if(ValidDict(dict))
        {
            if(complete)
            {
                complete(dict[@"Id"]);
            }
        }else
        {
            if(complete)
            {
                complete(@"");
            }
        }
        
    } error:^(NSError *error) {
        NSLog(@"%@", error);
        if(complete)
        {
            complete(@"");
        }
    }];
}


-(void)getWheelRewardRecordInfoComplete:(void(^)(NSArray * data))complete
{
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"/Api/v2/UserInfo/GetWheelRewardRecord" parameters:@{@"userId":[[XLAccountManager shareInstance]model].Id} resultClass:[XLWheelRecordModel class]] subscribeNext:^(id x) {
        NSArray * data = (NSArray *)x;
        if(complete)
        {
            complete(data);
        }
        
    } error:^(NSError *error) {
        NSLog(@"%@", error);
        if(complete)
        {
            complete(nil);
        }
    }];
}


-(void)getAddWheelFortunComplete:(void(^)(BOOL isSuccess))complete
{
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"/api/v2/UserInfo/AddWheelFortun" parameters:@{@"userId":[[XLAccountManager shareInstance]model].Id} resultClass:nil] subscribeNext:^(id x) {
//        NSDictionary * dict = (NSDictionary *)x;
        if(complete)
        {
            complete(YES);
        }
        
    } error:^(NSError *error) {
        NSLog(@"%@", error);
        if(complete)
        {
            complete(NO);
        }
    }];
}

-(void)getWheelRewardTotalComplete:(void(^)(XLUserShareModel * model))complete
{
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"/Api/v2/UserInfo/GetWheelRewardTotal" parameters:@{@"userId":[[XLAccountManager shareInstance]model].Id} resultClass:[XLUserShareModel class]] subscribeNext:^(id x) {
        XLUserShareModel * model = (XLUserShareModel *)x;
        if(complete)
        {
            complete(model);
        }
        
    } error:^(NSError *error) {
        NSLog(@"%@", error);
        if(complete)
        {
            complete(nil);
        }
    }];
}


@end
